package com.example.administrator.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by Administrator on 2020/11/19.
 */

public class TwoActivity extends AppCompatActivity {
    Button button;
    private EditText usernameEd;
    private EditText scoreEd;
    private EditText ispassedEd;
    private Button startActivityBtn;
    private String studentName;
    private String ispassedStr;
    private String scoreStr;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        initView();
        initEvent();


    }

    private void initEvent() {

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        startActivityBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                //创建intent对象
                initData();
                int score = Integer.parseInt(scoreStr);
                boolean ispassed = Boolean.parseBoolean(ispassedStr);
                Intent intent = new Intent(TwoActivity.this, TreeActivity.class);
                intent.putExtra("studentName", studentName);
                intent.putExtra("score",score);
                intent.putExtra("ispassed",ispassed);
                Toast.makeText(TwoActivity.this, "姓名：" + studentName, Toast.LENGTH_SHORT).show();
                startActivity(intent);
            }
        });
    }

    private void initData() {
        studentName = usernameEd.getText().toString() + "";
        scoreStr = scoreEd.getText()+"";
        ispassedStr = ispassedEd.getText()+"";


    }

    private void initView() {
        usernameEd = findViewById(R.id.username_et);
        scoreEd = findViewById(R.id.score_et);
        ispassedEd = findViewById(R.id.ispassed_et);
        startActivityBtn = findViewById(R.id.startctivity_btn);
        button = findViewById(R.id.button1);
    }
}
